<template>

    <div class="container">
        <h1>登陆注册</h1>
        <el-form :model="formRegister" label-width="120px">
            <el-form-item label="username">
                <el-input v-model="formRegister.username"></el-input>
            </el-form-item>
            <el-form-item label="password">
                <el-input v-model="formRegister.password" type="password"></el-input>
            </el-form-item>
            <el-form-item label="name">
                <el-input v-model="formRegister.name" />
            </el-form-item>
            <el-form-item label="gender">
                <el-radio-group v-model="formRegister.gender">
                    <el-radio label="男" size="small">
                        男
                    </el-radio>
                    <el-radio label="女" size="small">
                        女
                    </el-radio>
                </el-radio-group>
            </el-form-item>
            <el-form-item label="age">
                <el-slider v-model="formRegister.age" show-input />
            </el-form-item>
            <el-form-item label="type">
                <el-radio-group v-model="formRegister.type">
                    <el-radio-button label="student" />
                    <el-radio-button label="teacher" />
                </el-radio-group>
            </el-form-item>
        </el-form>

        <el-button @click="goSubmit">提交</el-button>

    </div>


</template>

<script setup>
import { reactive, ref, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import {reegisterStudent} from '../API/ApiMethod'
import { ElTable, ElRadioGroup, ElForm, ElSlider, ElDescriptions, ElMessage } from 'element-plus';
import {AES_Encrypt} from '../crypto/index'
components: {
    ElTable
    ElForm
    ElRadioGroup
    ElSlider
    ElDescriptions,
        ElMessage
}
const formRegister = reactive({
    username: '',
    password: '',
    name: '',
    gender: '',
    age: 0,
    type: ''
})
let router = useRouter()
function goSubmit() {
    console.log('submit')
    if (formRegister.username != "" && formRegister.password != "" && formRegister.name != "" && formRegister.gender != "" && formRegister.age != 0&&formRegister.type!='') {
        formRegister.password = AES_Encrypt(formRegister.password)
        reegisterStudent(formRegister.username,formRegister.password,formRegister.name,formRegister.gender,formRegister.age,formRegister.type).then(res=>{
            console.log(res)
        }).catch(err=>{
            throw err
        })
        router.push({
            name: 'login'
        })
    }
}
onMounted(() => {
})

</script>

<style scoped>
.container {
    width: 60%;
    margin: 0 auto;
}

.container h1 {
    text-align: center;
}
</style>